package com.imay.live.view.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.imay.base.util.StringUtil;
import com.imay.live.R;

/**
 * Created by liangzhenxiong on 2017/04/11 0011.
 */

public class GameTitleView extends LinearLayout {


    public GameTitleView(Context context) {
        super(context);
    }

    public GameTitleView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public GameTitleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


   public void bindView(Context context,String tabName) {
        setOrientation(HORIZONTAL);
        View view = new View(context);
        view.setBackgroundColor(getResources().getColor(R.color.color_ff));
        LayoutParams params = new LayoutParams((int) getResources().getDimension(R.dimen.gametitle_leftwith), ViewGroup.LayoutParams.MATCH_PARENT);
        params.topMargin = (int) getResources().getDimension(R.dimen.gametitle_top);
        params.leftMargin = (int) getResources().getDimension(R.dimen.gametitle_padding);
        params.rightMargin = (int) getResources().getDimension(R.dimen.gametitle_padding);
        params.bottomMargin = (int) getResources().getDimension(R.dimen.gametitle_top);
        params.gravity = Gravity.CENTER_VERTICAL;
        addView(view, params);
        TextView textView = new TextView(context);
        LayoutParams textparams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        textparams.gravity = Gravity.CENTER_VERTICAL;
        textView.setGravity(Gravity.CENTER_VERTICAL);
        textView.setTextSize(15);
        addView(textView, textparams);
        textView.setTextColor(getResources().getColor(R.color.text_20));
        textView.setText(StringUtil.isEmpty(tabName)?context.getResources().getString(R.string.str_imay_gmaelive):tabName);
        setBackgroundColor(getResources().getColor(R.color.bg_window));
    }

    public void setViewVisible(boolean visible){
            setVisibility(visible?VISIBLE:GONE);

    }
    

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((int) getResources().getDimension(R.dimen.gametitle_with),MeasureSpec.EXACTLY));

    }
}
